package JDBC_Test.Student;

import java.sql.*;
import java.util.*;

public class JDBCUtil {
	private static ResourceBundle rb = ResourceBundle.getBundle("JDBC_Test.Student.jdbc");
	
	private static String className = rb.getString("driver");
	private static String url = rb.getString("url");
	private static String user = rb.getString("user");
	private static String password = rb.getString("password");
	
	//加载驱动
	static {
		try {
			Class.forName(className);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 获得连接
	 * @throws SQLException 
	 */
	public static Connection geConnection() throws SQLException {
		return DriverManager.getConnection(url,user,password);
	}
	/**
	 * 关闭连接
	 * @param connection
	 * @param st
	 * @param rs
	 */
	public static void close(Connection connection,Statement st,PreparedStatement ps) {
		try {
			if(ps!=null) {
				ps.close();
				ps = null;
			}
			if(st!=null) {
				st.close();
				st = null;
			}
			if(connection!=null) {
				connection.close();
				connection = null;
			}
		} catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	public static void main(String[] args) throws SQLException {
		Connection con = JDBCUtil.geConnection();
		System.out.println(con);
	}
	
	private JDBCUtil() {
		
	}
	
}
